//
//  RootViewController.m
//  UI6_课后作业练习
//
//  Created by dllo on 15/11/16.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "IconViewController.h"
#import "ListViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) IconViewController *iconVC;
@property (nonatomic, retain) ListViewController *listVC;
@property (nonatomic, retain) UISegmentedControl *segmentC;


@end

@implementation RootViewController

- (void)dealloc
{
    [_iconVC release];
    [_listVC release];
    [_segmentC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.iconVC = [[IconViewController alloc] init];
    [self addChildV111iewController:self.iconVC];
    [self.view addSubview:self.iconVC.view];
    [_iconVC release];
    
    self.listVC = [[ListViewController alloc] init];
    [self addChildViewController:self.listVC];
    [self.view addSubview:self.listVC.view];
    [_listVC release];
    
    self.segmentC = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"图标", @"列表", nil]];
    self.segmentC.center = CGPointMake(180, 35);
    [self.segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.segmentC];
    [_segmentC release];
    
    
    
    
}

- (void)segmentAction:(UISegmentedControl *)sender
{
    if (0 == sender.selectedSegmentIndex) {
        [self.view bringSubviewToFront:self.iconVC.view];
    }
    if (1 == sender.selectedSegmentIndex) {
        [self.view bringSubviewToFront:self.listVC.view];
    }
    [self.view bringSubviewToFront:sender];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
